<?php
/**
 * Created by PhpStorm.
 * User: bevan
 * Date: 2018/1/3
 * Time: 下午2:55
 */

namespace app\admin\controller;

use app\admin\facade\Options;
use app\common\controller\Admin;
use app\common\model\OptionsModel;
use think\facade\Request;

class OptionsController extends Admin
{
    /**
     *
     * @method 获取所有的options
     * @version
     * @User: bevan
     * @return
     */
    public function index()
    {
        $options = OptionsModel::all();
        return ['code' => 1001, 'msg' => '获取成功', 'data' => $options];
    }

    /**
     *
     * @method 获取某一个option
     * @version
     * @User: bevan
     * @param $id 主键
     * @return
     */
    public function read($type)
    {
        return Options::read($type);
    }

    /**
     *
     * @method 更新某个option
     * @version
     * @User: bevan
     * @param $id 主键
     * @return
     */
    public function update($type)
    {
        $data = Request::param();
        unset($data['type']);
        return Options::update($type, $data);
    }
    /**
     * 删除缓存
     */
    public function clearCache()
    {
        cmf_clear_cache();
        return json(['code' => 1001, 'msg' => '清理成功', 'data' => []]);
    }
}
